﻿CREATE PROCEDURE [dbo].[utl_AddHousekeepingToAllTables]
@Force BIT=0
AS
BEGIN
	DECLARE @True  BIT; SET @True  = 1
	DECLARE @False BIT; SET @False = 0
	
	DECLARE @ID      INT
	DECLARE @Table   sysname
	
	DECLARE @Tables  TABLE (
				ID INTEGER IDENTITY(1, 1) PRIMARY KEY, 
				TableName sysname
			)
	
	INSERT INTO @Tables
	  (
	    TableName
	  )
	SELECT TableName
	FROM   dbo.fn_Tables()
	
	SELECT @ID = MIN(ID)
	FROM   @Tables
	
	WHILE @ID IS NOT NULL
	BEGIN
	    SELECT @Table = TableName
	    FROM   @Tables
	    WHERE  ID = @ID
	    
	    EXECUTE [dbo].[utl_AddHousekeeping] @Table, @Force
	    
	    SELECT @ID = MIN(ID)
	    FROM   @Tables
	    WHERE  ID > @ID
	END
END

